<?php

/**
 * 搜索模型
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: ContentModel.class.php v1.0 2014-06-13 17:27:03 $
 */
namespace Home\Model;
class SearchModel extends CommonModel{
    /**
     *  获得关键字SQL
     *
     * @access    private
     * @return    string
     */
    function GetKeywordSql($Keywords){
        $ks = explode(' ', $Keywords);
        $kwsql = '';
        $kwsqls = array();
        foreach($ks as $k){
            $k = trim($k);
            if(strlen($k)<1){
                continue;
            }
            if(ord($k[0])>0x80 && strlen($k)<2){
                continue;
            }
            $k = addslashes($k);
            
            $kwsqls[] = " CONCAT(title,' ',writer,' ',keywords) LIKE '%$k%' ";
            
        }
        if(!isset($kwsqls[0])){
            return '';
        }else{
            $kwsql = join(' OR ',$kwsqls);
            return $kwsql;
        }
    }
}
